<template>
   <h2>录入房价</h2>
   <input type="button" value="房价列表" @click="wukmkxxx">
   <table>
    <tr>
        <td>房价名称</td>
        <td>
            <input type="text" v-model="poisk.name">
        </td>
    </tr>
    <tr>
        <td>房价</td>
        <td>
            <input type="text" v-model="poisk.price">
        </td>
    </tr>
    <tr>
        <td>房间类型</td>
        <td>
            <select v-model="poisk.typeid">
                <option value="">请选择</option>
                <option :value="is.id" v-for="is in type">{{ is.rname }}</option>
            </select>
        </td>
    </tr>
    <tr>
        <td></td>
        <td>
            <input type="button" value="添加" @click="addowmmwwws">
        </td>
    </tr>
   </table>
  </template>
  
  <script setup lang="ts">
  import {onMounted, reactive, toRefs} from 'vue'
  import {useRouter,useRoute} from 'vue-router'
  import axios from 'axios'
  const router=useRouter()
  const route=useRoute()

  let data=reactive({
    type:[],
    poisk:{
        name:'',
        price:'',
        typeid:''
    }
  })
  let {type,poisk} =toRefs(data)

  onMounted(()=>{
    gettype()
  })

  const gettype=()=>{
    axios({
        url:'/api/Price/Bindtype',
        method:'get'
    })
    .then(res=>{
        type.value=res.data.data;
    })
  }

  const addowmmwwws=()=>{
    if(poisk.value.name==""){
        alert("房价名称不能为空")
        return;
    }
    if(poisk.value.price==""){
        alert("房价不能为空")
        return;
    }
    if(poisk.value.typeid==""){
        alert("房间类型不能为空")
        return;
    }
    let obj={
        "typeid": poisk.value.typeid,
  "pname": poisk.value.name,
  "price": poisk.value.price,
  "pstates": 1,
  "isdel": false
    }
    axios({
        url:'/api/Price/Addprice',
        method:'post',
        data:obj
    })
    .then(res=>{
        if(res.data.data==1){
            alert("添加房价信息成功")
            router.push('showprice')
        }else{
            alert("添加房价信息失败")
        }
    })
  }

  const wukmkxxx=()=>{
    router.push('showprice')
  }
  </script>
  
  <style scoped>
  
  </style>